<?php
/**
 * Created by PhpStorm.
 * User: 墨染
 * Date: 2020/12/15
 * Time: 17:25
 */

/**
 * 1.字符串
 */
$x = "Hello world!";
echo $x;
echo "<br>";
$x = 'Hello world!';
echo $x;
echo PHP_EOL;

/**
 * 2.整型
 */
$x = 5985;
var_dump($x);
echo "<br>";
$x = -345; // 负数
var_dump($x);
echo "<br>";
$x = 047;
var_dump($x);
echo PHP_EOL;

/**
 * 3.浮点型
 */
$x = 10.365;
var_dump($x);
echo "<br>";
$x = 2.4e3;
var_dump($x);
echo "<br>";
$x = 8E-5;
var_dump($x);
echo PHP_EOL;

/**
 * 4.布尔型
 */
$x = true;
$y = false;

/**
 * 5.数组
 */
$cars = array("Volvo", "BMW", "Toyota");
var_dump($cars);
echo PHP_EOL;

/**
 * 6.对象
 */
class Car
{
    var $color;
    function __construct($color="green")
    {
        $this->color = $color;
    }
    function what_color() {
        return $this->color;
    }
}

function print_vars($obj) {
    foreach (get_object_vars($obj) as $prop => $val){
        echo "\t$prop = $val\n";
    }
}

// 实例一个对象
$herbie = new Car("white");

// 显示 herbie 属性
echo "\therbie: Properties:\n";
print_vars($herbie);
echo PHP_EOL;

/**
 * 7.NULL值
 */
$x = "Hello world!";
$x = null;
var_dump($x);
echo PHP_EOL;
?>

